package recursion;

import java.util.Arrays;

/**
 * @Program: dataOJ->Mase
 * @Description: 迷宫问题，求解路径
 * @Author: Tansty
 * @Date: 2022-02-16 21:56
 * @Version： 1.0
 **/

public class Mase {
    public static void main(String[] args) {
        int[][] mase = new int[8][7];
        for (int i = 0; i < mase.length; i++) {
            mase[i][0] = 1;
            mase[i][6] = 1;
        }
        for (int i = 0; i < 7; i++) {
            mase[0][i] = 1;
            mase[7][i] = 1;
        }
        mase[3][1] = 1;
        mase[4][1] = 1;

        setWay(mase,1,1);
        for (int[] ints : mase) {
            for (int j = 0; j < 7; j++) {
                System.out.print(ints[j] + " ");
            }
            System.out.println();
        }
    }
    public static boolean setWay(int[][] map,int start,int stop){
        //判断是否已经走到目的地点
        if(map[6][5] == 2){
            return true;
        }
        //如果该点还没有走过那就走
        if(map[start][stop]==0){
            map[start][stop] = 2;
            //右 -》 下 -》上 -》 左
            if(setWay(map,start+1,stop)){
                return true;
            }else if(setWay(map,start,stop+1)){
                return true;
            }else if(setWay(map,start,stop-1)){
                return true;
            }else if(setWay(map,start-1,stop)){
                return true;
            }else {
                //代表该点走不通
                map[start][stop] = 3;
                return false;
            }
        }else{
            return false;
        }

    }
}
